<template>
  <zm-dialog
    title="激活确认"
    :visible.sync="value"
    append-to-body
    size="small"
    :before-close="dialogClose"
    :close-on-click-modal="false"
  >
    <p class="bc-detail lh40 plr10">确认激活此批次卡券?确认后该券卡即可正常使用，请慎重！</p>
    <el-form :model="form" inline ref="form" label-width="110px" label-position="right">
      <el-form-item label="售货方式：" prop="saleTypeName">
        <div class="w120">{{ form.productInfo.saleTypeName|| '--' }}</div>
      </el-form-item>
      <el-form-item label="产品类型：" prop="productType">
        <div class="w240">{{ form.productInfo.productType|| '--' }}</div>
      </el-form-item>
      <el-form-item label="归属业务员：" prop="belongAccountName">
        <div class="w120">{{ form.belongAccountName|| '--' }}</div>
      </el-form-item>
      <el-form-item label="数量：" prop="number">
        <div class="w240">{{ form.productInfo.number|| '--' }}张</div>
      </el-form-item>
      <el-form-item label="销售单总金额：" prop="saleTotalPrice">
        <div class="w120">{{ form.productInfo.saleTotalPrice|| '--' }}元</div>
      </el-form-item>
      <el-form-item label="有效期：">
        <div class="w240">{{ expiredTypeName }}</div>
      </el-form-item>
      <div class="bc-detail " v-if="form.saleType === '1' && form.codeIdDetail">
        <el-form-item :label="areaLabel+'：'">
          <div v-for="(item, index) in form.codeIdDetail" :key="index">
            {{item.left}}--{{item.right}}
          </div>
        </el-form-item>
      </div>
    </el-form>
    <div slot="footer" class="tr">
      <el-button size="small" @click="dialogClose">取消</el-button>
      <el-button size="small" type="primary" @click="submit">确定</el-button>
    </div>
  </zm-dialog>
</template>

<script>
import dialogMixin from '@/mixins/dialogMixin'
import { active } from '@/api/src/saleOrder'

export default {
  components: { },
  mixins: [dialogMixin],
  props: {},
  data () {
    return {
      form: {

      },
      expiredTypeName: '--'
    }
  },
  computed: {
    areaLabel () {
      // 类型：1兑换券，2卖品券，3点卡，4次卡，5优惠券
      let productType = ''
      if (
        this.obj.productInfo.productTypeId === '1' ||
        this.obj.productInfo.productTypeId === '2' ||
        this.obj.productInfo.productTypeId === '5'
      ) {
        productType = '券号区间'
      } else if (
        this.obj.productInfo.productTypeId === '3' ||
        this.obj.productInfo.productTypeId === '4'
      ) {
        productType = '卡号区间'
      } else {
        productType = '券号区间'
      }
      return productType
    }
  },
  created () {
    this.getInfo()
  },
  methods: {
    getInfo () {
      this.form = this.obj
      const floatStr = this.obj.floatUnit === 'day' ? '天' : this.obj.floatUnit === 'week' ? '周' : '月'
      switch (this.obj.expiredType) {
        case '1':
          this.expiredTypeName = this.obj.startDate + '-' + this.obj.endDate
          break
        case '2':
          this.expiredTypeName = '绑定后' + this.obj.floatDay + floatStr + '有效'
          break
        case '3':
          this.expiredTypeName = '销售后' + this.obj.floatDay + floatStr + '有效'
          break
      }
    },
    async submit () {
      // const form = {
      //   ...this.form,
      //   ...{ id: this.obj.id },
      //   ...{ saleType: this.obj.saleType }
      // }

      const form = {
        id: this.obj.id,
        expiredType: this.obj.expiredType,
        startDate: this.obj.startDate,
        endDate: this.obj.endDate,
        floatDay: this.obj.floatDay,
        floatUnit: this.obj.floatUnit,
        codeIdDetail: this.obj.codeIdDetail,
        saleType: this.obj.saleType
      }
      await active(form)

      this.$message.success('激活成功')
      this.$emit('after')
      this.close()
    }
  }
}
</script>
